<?php

namespace Modules\Manager\Http\Controllers\Admin;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use Modules\Manager\Entities\Module;
use Illuminate\Http\Request;
use Modules\Manager\Http\Requests\ModuleRequest;

class ModuleController extends Controller
{

    use ResponseData;
    public function list(Module $module,Request $request){
        $size = $request->input('size',10);
        $data = $module->orderBy('sort','asc')->paginate($size);
        return $this->success($data);
    }
    public function store(Module $module,ModuleRequest $request){
        $data = $request->all();
        $module->fill($data);
        $module->save();
        return $this->success('保存成功');
    }
    public function edit(Module $module,Request $request){
        $data = $module->find($request->id);
        return $this->success($data);
    }
    public function update(Module $module,Request $request){
        $data = $module->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(Module $module,Request $request){
        $data = $module->find($request->id);
        $data->delete();
    }
}
